package com.woniu.woniuk16.exception;

import com.woniu.woniuk16.model.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.lang.reflect.UndeclaredThrowableException;

@RestControllerAdvice
public class WoniuExceptionHandler {

    @ExceptionHandler(WoniuException.class)
    public Result woniuException(WoniuException woniuException){
        return Result.builder().message(woniuException.getMessage()).code(woniuException.getCode()).build();
    }

    @ExceptionHandler(MesException.class)
    public Result MesException(MesException woniuException){
        return Result.builder().message(woniuException.getMessage()).code(10086).build();
    }

    @ExceptionHandler(Exception.class)
    public Result Exception(Exception e){
        e.printStackTrace();
        return Result.getInstance(null).setMessage("有异常").setCode(10000);
    }
}
